#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int b[500005]; vector<vector<int>> a; vector<int> sa;
vector<int> f; vector<int> g; vector<pair<int, int>> h; int buc[MAXN];
char buf[1 << 24], *S, *T; char gc() {return S == T && (T = (S = buf) + fread(buf, 1, 1 << 24, stdin)) == buf ? 0 : *S++;}
int read() {
	char ch; while ((ch = gc()) <= ' '); int x = ch - '0';
	while ((ch = gc()) > ' ') x = 10 * x + ch - '0'; return x;
}
int main() {
	freopen("list.in", "r", stdin); freopen("list.out", "w", stdout);
	int n = read(); a.resize(n); int mx = 0;
	for (int i = 0; i < n; i++) {
		int k = read(); while (k--) {
			a[i].push_back(read()), mx = max(mx, a[i].back());
			sa.push_back(a[i].back());
		}
	}
	sort(sa.begin(), sa.end()); int N = unique(sa.begin(), sa.end()) - sa.begin(); sa.resize(N);
	int c = read(); for (int i = 1; i <= n; i++) b[i] = read();
	long long F = 0, G = 0;
	for (int i = 0; i < n; i++) {
		if (a[i].empty()) continue;
		int k = a[i].size(); int X = lower_bound(sa.begin(), sa.end(), a[i][0]) - sa.begin() + 1;
		F -= 1ll * b[buc[X]] * buc[X]; buc[X]++; F += 1ll * b[buc[X]] * buc[X];
		for (int j = 0; j < k; j++) {
			if (j + 1 == k) G += c;
			else {
				int dis = a[i][j + 1] - a[i][j];
				h.push_back({dis, lower_bound(sa.begin(), sa.end(), a[i][j + 1]) - sa.begin() + 1});
				F += 1ll * c * dis; g.push_back(dis); f.push_back(dis);
			}
		}
	}
	// printf("%lld %lld\n", F, G);
	sort(f.begin(), f.end(), greater<>());
	sort(g.begin(), g.end(), greater<>());
	sort(h.begin(), h.end(), greater<>());
	// for (int x : f) printf("%d ", x); puts("");
	// for (int x : g) printf("%d ", x); puts("");
	int m1 = f.size(), m2 = g.size(), m3 = h.size();
	long long res; vector<int> resV; int ti = 1;
	if (0 < m1) ti = max(ti, f[0] + 1);
	if (0 < m2) ti = max(ti, g[0] + 1);
	if (0 < m3) ti = max(ti, h[0].first + 1);
	res = F + ti * G; resV.push_back(ti); // printf("%d -> %lld\n", ti, F + ti * G);
	for (int i = 0, j = 0, k = 0; i < m1 || j < m2 || k < m3; ) {
		bool f1 = i < m1 && (j == m2 || f[i] >= g[j]) && (k == m3 || f[i] >= h[k].first);
		bool f2 = j < m2 && (i == m1 || g[j] >= f[i]) && (k == m3 || g[j] >= h[k].first);
		bool f3 = k < m3 && (i == m1 || h[k].first >= f[i]) && (j == m2 || h[k].first >= g[j]);
		// printf("?? %d %d %d %d %d %d\n", i, j, k, f1, f2, f3);
		if (f1) {int _ = i; while (_ < m1 && f[_] == f[i]) F -= 1ll * f[_++] * c; i = _;}
		if (f2) {int _ = j; while (_ < m2 && g[_] == g[j]) G += c, _++; j = _;}
		if (f3) {int _ = k; while (_ < m3 && h[_].first == h[k].first) F -= 1ll * b[buc[h[_].second]] * buc[h[_].second], buc[h[_].second]++, F += 1ll * b[buc[h[_].second]] * buc[h[_].second], _++; k = _;}
		ti = 1;
		if (i < m1) ti = max(ti, f[i] + 1);
		if (j < m2) ti = max(ti, g[j] + 1);
		if (k < m3) ti = max(ti, h[k].first + 1);
		if (res > F + ti * G) res = F + ti * G, resV = {ti};
		else if (res == F + ti * G) resV.push_back(ti);
		// printf("%d -> %lld\n", ti, F + ti * G);
	}
	printf("%lld %d\n", res, (int)resV.size());
	reverse(resV.begin(), resV.end()); for (int x : resV) printf("%d ", x);
}
/*
run list < list1.in > list1.out
run list < list3.in > list3.out
run list < list4.in > list4.out
run list < list5.in > list5.out
run list < list6.in > list6.out
run list < list7.in > list7.out
diff list1.out list1.ans -Z
diff list3.out list3.ans -Z
diff list4.out list4.ans -Z
diff list5.out list5.ans -Z
diff list6.out list6.ans -Z
diff list7.out list7.ans -Z
*/